#include<bits/stdc++.h>
#define int long long
#define N 1005
using namespace std;
int n;
int a[N],b[N];
int ans;
vector<int> f;
map<vector<int>,bool> vis;
void dfs(int x,int y){
    if(x==n&&y==n){
        if(!vis[f]) ans++,vis[f]=1;
        return;
    }
    if(x!=n) f.emplace_back(b[y]),dfs(x+1,y),f.pop_back();
    if(y!=n) f.emplace_back(a[x]),dfs(x,y+1),f.pop_back();
}
signed main(){
    freopen("zha.in","r",stdin);
    freopen("zha.out","w",stdout);
    scanf("%lld",&n);
    for(int i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(int i=1;i<=n;i++) scanf("%lld",&b[i]);
    dfs(1,1);
    printf("%lld",ans);
    return 0;
}